package utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ShellUtils {
    public static String convertStreamToStr(InputStream is) throws IOException {
        InputStreamReader isr = new InputStreamReader(is,"GBK");
        BufferedReader br = new BufferedReader(isr);
        StringBuilder sb = new StringBuilder();
        String line;
        while (( line = br.readLine()) != null) {
            sb.append(line).append("\n");
        }
        return sb.toString();
    }
    public static String run(String cmd){
        try {
            String res = convertStreamToStr(Runtime.getRuntime().exec(cmd,null,null).getInputStream());
            return res;
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return "";
    }

}
